LinksPortlet = Class.extend({
	init: function()	{
		this.name = "LinksPortlet";
	},
	
	onBegin: function()	{
		this.model = {};
	},

	run: function()	{
		this.getPortletPlaceholder().drawToCanvas(this.render());
	}
}).implement(PortletInterface).implement(RenderInterface);

InviteLinkPortlet = Class.extend({
	init: function()	{
		this.name = "InviteLinkPortlet";
	},
	
	onBegin: function()	{
		this.model = {};
	},

	run: function()	{
		this.getPortletPlaceholder().drawToCanvas(this.render());
	}
}).implement(PortletInterface).implement(RenderInterface);
EventLinkPortlet = Class.extend({
	init: function()	{
		this.name = "EventLinkPortlet";
	},
	
	onBegin: function()	{
		this.model = {};
	},

	run: function()	{
		this.getPortletPlaceholder().drawToCanvas(this.render());
	}
}).implement(PortletInterface).implement(RenderInterface);
TwitterFollowPortlet = Class.extend({
	init: function()	{
		this.name = "TwitterFollowPortlet";
	},
	
	onBegin: function()	{
		this.model = {};
	},

	run: function()	{
		this.getPortletPlaceholder().drawToCanvas(this.render());
	}
}).implement(PortletInterface).implement(RenderInterface);

ContactPortlet = Class.extend({
	init: function()	{
		this.name = "ContactPortlet";
	},
	
	onBegin: function()	{
		this.model = {};
	},

	run: function()	{
		this.getPortletPlaceholder().drawToCanvas(this.render());
	}
}).implement(PortletInterface).implement(RenderInterface);

CatchWordBrowserPortlet = Class.extend({
	init: function()	{
		this.name = "CatchWordBrowserPortlet";
	},
	
	onReloadPage: function()	{
		this.checkActive();
	},
	
	checkActive: function()	{
		var request = this.getRequest();
		var page = request.getParam('page');
		var curId = request.getParam('id');
		this.requestForEffectiveResource('ContentPlaceholder').find('[tid]').each(function(){
			var tid = $(this).attr('tid');
			if (tid == curId)	{
				$(this).addClass('active');
			} else {
				$(this).removeClass('active');
			}
		});
	},
	
	run: function()	{
		var obj = this;
		obj.getPortletPlaceholder().drawToCanvas(obj.render());
		this.onAjax('catchword', 'browse-catch-word', {}, 'GET', {
			'onSuccess': function(ret)	{
				var model = {};
				model.catchwords = Array();
				for(var i in ret)	{
					var row = ret[i];
					var contextID = row.contextID;
					if (typeof model.catchwords[contextID] == 'undefined')	{
						model.catchwords[contextID] = {};
						model.catchwords[contextID].context = row.context;
						model.catchwords[contextID].catches = Array();
					}
					model.catchwords[contextID].catches.push(row);
				}
				obj.requestForEffectiveResource('ContentPlaceholder').html(obj.renderView('Content', model));
				
				obj.checkActive();
			}
		});
	}
}).implement(PortletInterface).implement(RenderInterface).implement(AjaxInterface);

TwitterUpdatePortlet = Class.extend({
	init: function()	{
		this.name = "TwitterUpdatePortlet";
	},
	
	run: function()	{
//		var template = $('<script></script>').append($(this.requestForResource('TwitterRender')).html());
//		this.getPortletPlaceholder().drawToCanvas(template);
	}
}).implement(PortletInterface).implement(RenderInterface);

BrowserTogglePlugin = Class.extend({
	init: function()	{
		this.name = "BrowserTogglePlugin";
	},
	
	onToggleBrowserContext: function(event)	{
		var target = event.target;
		$(target).parent().parent().find('.catchwords-placeholder').toggle();
	},
	
	onHtmlUpdated: function()	{
		$('.extension-point[extensionName="ContextBrowser"]').each(function(index, value) {
			if ($(value).find('div[flag="ContextBrowserToggle"]').length > 0)	{
				return;
			}
			$(value).append(tmpl('ContextBrowserToggle', {}));
			$(value).parent().find('.catchwords-placeholder').toggle();
		});
	}
}).implement(PluginInterface);
ProfileFinishPortlet = Class.extend({
	init: function()	{
		this.name = "ProfileFinishPortlet";
	},
	
	run: function()	{
		var obj = this;
		this.onAjax('user-ajax', 'check-finish-profile', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.model = {};
				var inc = 20;
				obj.model.finish = inc;
				obj.model.msgs = Array();
				if(ret.avatar != false) obj.model.finish += inc;
				else obj.model.msgs.push('<a href="#page/UserAvatarEdit">Bạn chưa cập nhật hình đại diện?</a>');
				if(ret.catches != false) obj.model.finish += inc;
				else obj.model.msgs.push('<a href="#page/UserExpertiseEdit">Bạn chưa cập nhật kinh nghiệm?</a>');
				if(ret.interest != false) obj.model.finish += inc;
				else obj.model.msgs.push('<a href="#page/UserInterestEdit">Bạn chưa cập nhật lĩnh vực quan tâm?</a>');
				if(ret.question != false) obj.model.finish += inc;
				else obj.model.msgs.push('<a onclick=\'generateEvent("MakeNewQuestion", {})\'>Bạn chưa đặt câu hỏi nào?</a>');
				if (obj.model.finish < 100)
					obj.getPortletPlaceholder().drawToCanvas(obj.render());
			}
		});
	}
}).implement(PortletInterface).implement(RenderInterface).implement(AjaxInterface);

NavMenuPortlet = Class.extend({
	init: function()	{
		this.name = "NavMenuPortlet";
	},
	
	run: function()	{
		var obj = this;
		obj.model = {};
		obj.model.menus = Array();
		obj.model.menus.push({topic:'Trước khi vào trường', topicID:1});
		obj.model.menus.push({topic:'Mới vào trường', topicID:1});
		obj.model.menus.push({topic:'Đang học', topicID:1});
		obj.model.menus.push({topic:'Sắp ra trường', topicID:1});
		obj.model.menus.push({topic:'Lập nghiệp', topicID:1});
		obj.getPortletPlaceholder().paintCanvas(obj.render());
	}
}).implement(PortletInterface).implement(RenderInterface);

